<template>
	<view>
		<u-form labelPosition="left" :model="user" ref="user">
			<u-form-item label="账号" prop="account">
				<view class="u-demo-block__content">
					<u--input v-model="user.account" placeholder="请输入账号" border="surround"></u--input>
				</view>
			</u-form-item>
			<u-form-item label="密码" prop="password">
				<view class="u-demo-block">
					<view class="u-demo-block__content">
						<u--input v-model="user.password" placeholder="请输入密码" border="surround" password></u--input>
					</view>
				</view>
			</u-form-item>
		</u-form>
		<u-button type="primary" text="登录" customStyle="margin-top: 10px" @click="loginByAccount(user)"></u-button>
		<u-button text="手机号验证码登录" customStyle="margin-top: 10px" @click="loginByPhone"></u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {
					account: "17608127794",
					password: "123456"
				}
			}
		},
		methods: {
			loginByAccount(user) {
				console.log(user)
				uni.request({
					url: "/user/loginByAccount",
					data: {
						// user: this.user,
						account: user.account,
						password: user.password
					},
					// method:'POST',
					success(res) {
						if (res.data.code == 200) {
							
							// 保存 token
							uni.setStorageSync('token', res.data.data);
							//跳到首页
							uni.switchTab({
								url: "/pages/index/index"
							})
						} else {
							console.log(res.data.msg)
						}
					}
				})
			},
			loginByPhone() {
				uni.redirectTo({
					url: "/pages/loginByPhone?userName="+this.user.account
				})
			}
		}
	}
</script>

<style>
</style>